 <%@ page language="java" pageEncoding="UTF-8"%>
<%@page import="com.iris.egrant.service.ServiceUtils"%>
<%@page import="com.iris.egrant.web.struts2.Struts2Utils"%>
<%@ include file="/common/taglibs.jsp"%>
<%@ include file="/common-app/taglibs.jsp"%>
<%@ include file="/common/meta.jsp"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title></title>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">
	<script type="text/javascript" src="${res}/js/proposal/irisPrpPrepare.js"></script>
	<script type="text/javascript" src="${res}/js/validate/irisvalidator.js"></script>
	<script type="text/javascript" src="${res}/js/autodisckey/autodisckey.js"></script>
	<script type="text/javascript" src="${res_app}/js/app/product.js"></script>
	 <script type="text/javascript">
	 
	 $(document).ready(function(){
		 var opFlag = "${param.flag }";
		 if (opFlag != "add"){
			 var parentTr= parent.$("#tblExecuteProducts").find(":radio:checked").parents("tr");
			 if (parentTr.length == 0){  //
				 return ;
			 }
			 $("textarea[name='achievement/summary1']").val(parentTr.find("textarea[name$='achievement/summary1']").val());
		  }
	 }); 
  	
  		//点击保存
	  function saveGroupMember()
		{
			var parentTable= parent.$("#tblExecuteProducts");
			bfSave();
			SavePersonsData();
			ValData();
			if(!valResult()){
				irisValShowMsg($("#saveProduct"));
				return false;
			}
			var url = document.URL;
			if(IsAdd())
			{
				addNewRowDeal(parentTable);
				addflag="1";
				parentTable.find("tr:last").find(":radio").attr("checked","checked");
			} 
			dataSave();
			if(confirm("保存成功，是否返回申请书页面"))parent.tb_remove();
			selectRadio = parentTable.find(":radio:checked");	//父页面选中的单选框
			selectTr = selectRadio.parents("tr");				//父页面选中的行
		}
  		
	  function IsAdd()
		{
			if(addflag=="1") return false;
			var url = document.URL;
			if(url.indexOf("flag=add")>0)
				return true;
			else
				return false;
		}
	  
	  //textarae处理
	  function bfSave(){
			$("textarea").each(function(){
			var val=$(this).val();
			//val = val.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/\n/g,"<br/>").replace(/\s/g,"&nbsp;").replace(/"/g,"&quot;");
			$("input[name='"+$(this).attr('name')+"_hidden']").val(val);
			}); 
		}

	  	//填写检查
	  function ValData()
		{	
			validate($("#groupMemberBasic01"),"项目成果表-->项目成果");
			validateByTabRow($("#groupMemberBasic02"),"项目考核指标表-->项目考核指标",1);

		}
	  
	  //校验方法重写
	  function validateByTabRow(obj, title, rowNum) {
			 
			 if(obj.attr("id") =='tblProducts'){
					
				 if ((obj.find("tr").length - 4) < rowNum)
						irisValaddMsg(messageTip.rowNum.replace("[name]", title).replace(
								"[num]", rowNum));
					}else if(obj.attr("id") =='tblProductsResearch'){
						if ((obj.find("tr").length - 10) < rowNum)
							irisValaddMsg(messageTip.rowNum.replace("[name]", title).replace(
									"[num]", rowNum));
					}else{
						if ((obj.find("tr").length - 2) < rowNum)
							irisValaddMsg(messageTip.rowNum.replace("[name]", title).replace(
									"[num]", rowNum));
					}
			 
			var childStr=">tr";
			var minus_cnt =1;
			var start_idx =2;
			if($("#"+obj.attr("id")+">tbody").length>0){
				childStr=">tbody>tr";
			}
			if($("#"+obj.attr("id")+">thead").length>0){
				minus_cnt= 0;
				start_idx =1;
			}
			$("#"+obj.attr("id")+childStr).each(
					function(index) {

						if (index >= start_idx) {
								rtitle = messageTip.rowIndex.replace("[name]", title)
								.replace("[index]", index - minus_cnt);
							validate($(this), rtitle);
						}
					});
		}
		
		
		//保存xml
		function SavePersonsData()
		{	
			var strXmlData = prePareXmlDataStand($("#dojoTabParent"),null);	
			 strXmlData = "<?xml version='1.0' encoding='UTF-8'?><data>" + strXmlData + "</data>";
			$("input[name='xmldata']").val(strXmlData);			
		}
		
		function dataSave()
		{
			var parentTable = parent.$("#tblExecuteProducts");
			var seletedRow=parentTable.find(":radio[checked='checked']").parents("tr");
			
			$("input:not(:radio:button),textarea").each(function(){
				
				var id=$(this).attr("name");
				var parentObj=null;
				if(id==null || id=="")
					return true;
				//获得父页面的对象
				parentObj=seletedRow.find("[name$='/"+id+"']");
				if(parentObj!=null){
					if(parentObj.is("span")){
						parentObj.text($(this).val());	//将值写回父页面
					}
					else{
						parentObj.val($(this).val());
					}
				}
				
			});
		}
		
		
		
		//实现checkbox检查接口，告知initControl() 函数 ，此控件由标签生成，绑定值与赋值逻辑有差异
		/*
		*
		*/
		 function isTagCheckBox(name){
			if(name.indexOf("isleader")!=-1)
				return true;
			if(name.indexOf("ismember")!=-1)
				return true;
			if(name.indexOf("isgetstartfund")!=-1)
				return true;
			
			return false;
		}
		
		 
		 function RegExpName(){
			 var name = $("#result_type_name").val();
			 name1 = name.replace(/，/g, "；")
			 $("#result_type_name1").val(name1);
		 }
		
		
		
		
		/*****************表格操作方法重写********************/
		 /**
		  * 限制Table行数 （重写）
		  * @param tableId表格id
		  * @param max最大行数
		  * @returns {Boolean}
		  */
		 function checkTabLimitRewrite(tableId,max,message)
		 {
		 	var maxLinNum=$("#"+tableId+">tbody>tr").length-1;
		 	
		 		if(maxLinNum>=max)
		 		{
		 			scmWarn(message);
		 			return false;
		 		}
		 	return true;
		 }
		  
		  /**
		   * 增加一行
		   * @param tableId表格Id
		   * @param radioId
		   * @param nNewRowPosition
		   * @param startRowIndex
		   */
		   function addNewRowDeal(table)
		  {
		  	if(table.attr("id")=='tblExecuteProducts'){
		  		var maxLinNum=table.find("tr").length-2;;//获得行数，减去表头和隐藏行
		  		var lineNum=""+(maxLinNum+1);
		  		
		  		var addHtml=table.find("tr")[1].innerHTML;//获得隐藏行的html,查找第二行
		  		addHtml=addHtml.replace(/\[index\]/g,lineNum);
		  		lineNum = (parseInt(lineNum, 10)-1).toString();//2011.12.13 行下标比行号小1(隐藏行下标[0]，第一行下标[00])
		  		if (lineNum.length==1)//如果是个位数，前面补0
		  			lineNum="0"+lineNum;
		  		addHtml=addHtml.replace(/\[0\]/g,"["+lineNum+"]");//替换html中行号
		  		addHtml=addHtml.replace(/\|/g,"/");//替换html中节点/的代替符"|"
		  		table.append("<tr>"+addHtml+"</tr>");//将html增加到最后
		  	}else{
		  		var maxLinNum=$("#"+table.attr("id")+">tbody>tr").length-1;//获得行数，减去表头和隐藏行
		  		var lineNum=""+(maxLinNum+1);
		  		
		  		var addHtml=table.find("tr")[1].innerHTML;//获得隐藏行的html,查找第二行
		  		addHtml=addHtml.replace(/\[index\]/g,lineNum);
		  		addHtml=addHtml.replace(/\[index\-1\]/g,maxLinNum);
		  		lineNum = (parseInt(lineNum, 10)-1).toString();//2011.12.13 行下标比行号小1(隐藏行下标[0]，第一行下标[00])
		  		if (lineNum.length==1)//如果是个位数，前面补0
		  			lineNum="0"+lineNum;
		  		addHtml=addHtml.replace(/\[0\]/g,"["+lineNum+"]");//替换html中行号
		  		addHtml=addHtml.replace(/\|/g,"/");//替换html中节点/的代替符"|"
		  		
		  		table.append("<tr >"+addHtml+"</tr>");//将html增加到最后
		  	}
		  } 
		  
		  
		 
  
  </script>
	<script type="text/javascript">
		var parenttbl = "tblExecuteProducts";
		var parentsel = "selExecuteProducts";
		var parentTable = parent.$("#tblExecuteProducts");
		var addflag="";
		var selectRadio = $();									//父页面选中的单选框
		var selectTr = $();		
	
		//初始化样式
		$(document).ready(function(){
			setTimeout("initControl('dojoTabParent')",1000);
			$("table.t_css").not("[id='finances']").not("[id='budget1']").each(function(){
				$(this).find("tr").not($(".cbTable").find("tr")).each(function(index){
					if(index%2==0)
						$(this).removeClass("li_1").addClass("li_2");
					else
						$(this).removeClass("li_2").addClass("li_1");
				});
			});
			$("table").not(".cbTable").addClass("table01"); 
		    $('div').find("[id^='checkbox_dyn_']").find("tr").removeClass("li_1").removeClass("li_2");
		    $('div').find("[id^='checkbox_dyn_']").find("td").css("border",'0px solid');
		    $('.buttonTable').removeClass("table01").css("border",'0px solid');
		    
			<c:if test="${param.flag=='view'}">
			//以下是查看页面
			DisabledAll2("input");
			DisabledAll2("select");
			DisabledAll2("textarea");
			$(".datepick-trigger").css("display","none");
			$('.color_red').text('');
			$(".button").remove();
			$(".tb_button").remove();
			$(".inputSelectButton").remove();
			$("img").not("#orgphotoImg").remove();
			</c:if> 
		});
		
		
		//查看 disabled 
		function DisabledAll2(tagName){
			$(tagName).not(".button_01").attr("disabled",true);
		}
		
		//证件类型改变时，证件号码填写检查逻辑
		function changeCardType(){
			var cardTypeObj = $("[name='basicinfo/card_type_value']");
			var cardCodeObj = $("[name='basicinfo/card_code']");
			
			if(cardTypeObj.val()=="1"){
				cardCodeObj.addClass("idCard");
				//cardCodeObj.attr("label","身份证");
			} else {
				cardCodeObj.removeClass("idCard");
				//cardCodeObj.attr("label","证件号码");
			}
		}
		
		
	</script>
  </head>

  <body >
  <c:set var="xmlStr">
   		<%=ServiceUtils.decodeFromDes3(Struts2Utils.getSession().getAttribute("encryptData").toString()) %>
   </c:set>
   <% Struts2Utils.getSession().removeAttribute("encryptData");%>
  	<x:parse xml="${xmlStr}" var="xmlData"/> 
  	<div style="position: relative;">
  				<div id="tabnav">
					<ul>
					<li class="down" id="tab1" onclick="changeTab(this.id)"><a href="###"><span>项目成果表</span></a></li>
					   <li  id="tab2" onclick="changeTab(this.id)"><a href="###"><span>项目考核指标表</span></a></li> 
					</ul>
		       </div>	
  	
   <div class="dojoTabPaneWrapperDiy" id="dojoTabParent" >
	<div id="fragment-tab1" class="tab_box" label="项目成果表" >	
		<table class="t_css table01" width="100%" border="0" cellpadding="0" id="groupMemberBasic01" cellspacing="1">
			<col width="20%">
			<col width="79%">
		<tr>
			<td colspan="6" class="t_bar2">项目成果</td>
		</tr>
		<tr>
			<td align="right"><span class="color_red">*</span>成果名称：</td>
				<td >
					<input name="proposal/result_name" value="<x:out select="$xmlData/data/proposal/result_name"/>" 
					label="成果名称" class="required" width="97%" style="height: 20px" maxlength="100"/>
				</td>
		</tr>
		<tr >
			<td align="right"><span class="color_red">*</span>成果类型：</td>
			<td>
				<c:set var="result_type_value"><x:out select="$xmlData/data/proposal/result_type_value"/></c:set>
				<c:set var="result_other"><x:out select="$xmlData/data/proposal/result_other" /></c:set>
				<cpt:checkbox name="proposal/result_type"  key="result_type2" onClick="RegExpName();" width="none" repeatColumn="5" value="${result_type_value }" otherId="result_other" lastOther="true" otherValueName="${result_other }"></cpt:checkbox>
				<input type="text" style="width:200px;"  maxlength="100"  name = "proposal/result_other" label="其他" id ="result_other" value ="<x:out select="$xmlData/data/proposal/result_other"/>"  />
				<input type="hidden" name="proposal/result_type_value" class="required" label="成果类型" id="result_type_value" value="<x:out select="$xmlData/data/proposal/result_type_value"/>" />
				<input type="hidden" id="result_type_name" name="proposal/result_type_name" value="<x:out select="$xmlData/data/proposal/result_type_name"/>" />
				<input type="hidden" id="result_type_name1" name="proposal/result_type_name1" value="<x:out select="$xmlData/data/proposal/result_type_name1"/>" />
			</td>
		</tr>
		<tr>
			<td align="right"><span class="color_red">*</span>对应的项目任务：</td>
			<td>
				<input name="proposal/result_goal" value="<x:out select="$xmlData/data/proposal/result_goal"/>" 
				label="对应的项目任务" class="required" maxlength="100" style="height: 20px" width="97%" />
			</td>
		</tr>
				 
	</table>
	<script type="text/javascript">
		showAllDateTag("groupMemberBasic01");
	</script>
</div>
  	
 <div id="fragment-tab2" class="tab_box" label="项目考核指标表" style="display:none" >				
	<div class="t_bar2">
		<span class="color_red">*</span>项目考核指标
	</div>
	<table  id="groupMemberBasic02" cellpadding="0" class="table01 t_css" width="100%"  border="0" cellpadding="0" style="*border-bottom: #a1c0dc 1px solid;">
			<thead >
					<tr style="border:1px solid #B7D1E6">
						<th class="TblHead" align="center"  width="5%">选择</th>
						<th class="TblHead" align="center"  width="5%">序号</th>
						<th class="TblHead" align="center"  width="15%">指标名称</th>
						<th class="TblHead" align="center"  width="17%">立项时已有指标值/状态</th>
						<th class="TblHead" align="center"  width="16%">中期指标值/状态</th> 
						<th class="TblHead" align="center"  width="17%">完成时指标值/状态</th> 
						<th class="TblHead" align="center"  width="25%">考核方式（方法）及评价手段</th>
					</tr>
			</thead>
			<tbody id="tab">
					<tr style="display:none">
						<td align="center" >
							<input type="radio" class="radiobutton" name="expradio" >
						</td>
						<td align="center" >
							<span name="experiences|experience[0]@seq_no" >[index]</span> 
						</td>
						<td align="center" >
							<input name="experiences|experience[0]|name" label="指标名称" value="" style="height: 20px; width:90%"  class="required input_text"  maxlength="100"/>
						</td>
						<td align="center" >
							<input name="experiences|experience[0]|has_target" label="立项时已有指标值/状态" style="height: 20px; width:90%"  value="" class="required input_text" maxlength="100" />
						 </td> 
						<td align="center">
							<input name="experiences|experience[0]|middle_target" label="中期指标值/状态" style="height: 20px; width:90%" value="" class="required input_text" maxlength="100" />
						</td> 
						<td align="center">
							<input name="experiences|experience[0]|finish_target" label="完成时指标值/状态" style="height: 20px; width:90%"  value="" class="required input_text" maxlength="100"/>
						</td> 
						<td align="center">
						    <input name="experiences|experience[0]|evaluation" label="考核方式（方法）及评价手段" style="height: 20px; width:90%"  value="" class="required input_text" maxlength="100"/>
						</td>
						
					</tr>
					
					<c:set value="0" var="index" scope="page"/>
					<x:forEach select="$xmlData/data/experiences/experience" var="experience">
					<c:choose>
						<c:when test="${index<10}" ><c:set value="0" var="flag" scope="page"/></c:when>
						<c:otherwise><c:set value="" var="flag" scope="page"/></c:otherwise>
					</c:choose>
					<tr >
						<td align="center">
							<input type="radio" class="radiobutton" name="expradio" >
						</td>
						<td align="center">
							<span name="experiences/experience[${flag}${index}]@seq_no" >
								<x:out select="$experience/@seq_no"/>
							</span> 
						</td>
						<td align="center">
							<input name="experiences/experience[${flag}${index}]/name"  
							 class="required input_text" label="指标名称" maxlength="100" style="height: 20px; width:90%"
							  value="<x:out select="$experience/name"/>"/>
						</td>
						<td align="center">
							<input name="experiences/experience[${flag}${index}]/has_target" 
							 class="required input_text"  label="立项时已有指标值/状态" maxlength="100"
							 style="height: 20px; width:90%" value="<x:out select="$experience/has_target"/>" />
						 </td> 
						<td align="center">
							<input name="experiences/experience[${flag}${index}]/middle_target" 
							label="中期指标值/状态" value="<x:out select="$experience/middle_target"/>" 
							style="height: 20px; width:90%" maxlength="100" class="required input_text" />
						</td> 
						<td align="center">
							<input name="experiences/experience[${flag}${index}]/finish_target" 
							label="完成时指标值/状态" value="<x:out select="$experience/finish_target"/>" 
							style="height: 20px; width:90%" maxlength="100" class="required input_text" />
						</td> 
						<td align="center">
							<input name="experiences/experience[${flag}${index}]/evaluation" 
							label="考核方式（方法）及评价手段" value="<x:out select="$experience/evaluation"/>" 
							style="height: 20px; width:90%" maxlength="100"	class="required input_text"/>
						</td> 
					</tr>
					<c:set value="${index+1 }" var="index" scope="page" />
				</x:forEach>
			</tbody>
		</table>
		<script type="text/javascript">
			showAllDateTag("groupMemberBasic02");
		</script>
		<br>

		<table width="98%" align="center" class="tb_button">
			<tr ><td>
			<input class="button" name="cmdAddbefore" type=button value="添加" onclick="if(checkTabLimit('groupMemberBasic02',999,'项目考核指标最多只能填写999条')){addNewRow('groupMemberBasic02');showDateTag('groupMemberBasic02');}try{top.resizeFrame();}catch(e){};">
			<input class="button" name="cmdMovePrev" type=button value="上移" onclick="movePrev('groupMemberBasic02','expradio')">
			<input class="button" name="cmdMoveNext" type=button value="下移" onclick="moveNext('groupMemberBasic02','expradio')">
			<input class="button" name="cmddel" type=button  value="删除" onclick="deleteSelectedRow('groupMemberBasic02','项目考核指标表')">
			</td></tr>
				</table>	
	</div>
		
		<table width="100%" align="center" class="buttonTable">
			<tr>
				<td align="center">
					<c:if test="${param.flag!='view'}">
					<input class="button_01" type="button" value=" 保 存 " id="saveProduct"
						onclick="saveGroupMember();">
					</c:if>
					<input class="button_01" type="button" value=" 取消 "
						onclick="parent.tb_remove();">
						<input type="hidden" value="" name="xmldata">
				</td>
			</tr>
		</table>
  </body>
  
 
</html>

